/*
 * Created on 2005/7/20
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.erp.app.web.report.simpleConReport;

/**
 * @author 32
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
import java.io.ByteArrayOutputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;

import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.erp.app.common.ProjectConstants;
import com.erp.app.common.select.beans.SelectDelegate;
import com.erp.app.report.genericInquiry.inquiryCriteria.beans.vo.InquiryCriteriaVO;
import com.erp.app.report.genericInquiry.inquiryDisplay.beans.vo.InquiryDisplayVO;
import com.erp.app.report.genericInquiry.inquiryMaster.beans.GenericInquiryMasterVO;
import com.erp.app.report.genericInquiry.inquiryOutput.beans.vo.InquiryOutputVO;
import com.erp.app.report.genericInquiry.inquirySp.beans.vo.InquirySpVO;
import com.erp.app.report.genericInquiry.GenericInquiryConstants;
import com.erp.app.report.genericInquiry.GenericInquirySearchForm;
import com.erp.framework.util.CommonUtil;
import com.erp.framework.util.user.User;
import com.lowagie.text.Cell;
import com.lowagie.text.Document;
import com.lowagie.text.Font;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Phrase;
import com.lowagie.text.Rectangle;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfPageEventHelper;
import com.lowagie.text.pdf.PdfTemplate;
import com.lowagie.text.pdf.PdfWriter;

public class SimpleConReport {
    
    private static Font compFt = null;
	private static Font titleFt = null;
	private static Font subTitleFt = null;
	private static Font emptyFt = null;
	private static Font sContentFtB = null;
	private static Font sContentFt = null;
	private static Font totalFt = null;
	private float pageXPos = 0;
	User editingUser = null;
	private String compLongName = "";
	private SelectDelegate sdg = new SelectDelegate();
    protected GenericInquirySearchForm form = null;
    private int compFontSiz = 0;
    private int titleFontSiz = 0;
    private int contentFontSiz = 0;
    private int totalFontSiz = 0;
    private int groupField = 0;
    private int groupHdrSpec = 0;
    private String pageSize = "";
    private String pageRotate = "";
    private String rptTitle = "";
    private String showCompLogo = "";
    private Image logo_img = null;
    private String defaultPageSize = "A4";
    private String a3PageSize = "A3";
    
    protected int getCompLogoLocation() {
        
        return 0;
    }
    
	protected Rectangle getPageSize() {
	    Rectangle r = null;
	    if (pageSize.equals(a3PageSize) && pageRotate.equals("Y")) {
	        r = PageSize.A3.rotate();
	    } else if (pageSize.equals(a3PageSize) && !pageRotate.equals("Y")) {
	        r = PageSize.A3;
	    } else if (pageSize.equals(defaultPageSize) && pageRotate.equals("Y")) {
	        r = PageSize.A4.rotate();
	    } else if (pageSize.equals(defaultPageSize) && !pageRotate.equals("Y")) {
	        r = PageSize.A4;
	    }
	    return r;
	}
	
	protected int getTblColNo() {
	    return getDisplayVO().size() - 1;
	}
	
	protected int[] getRsltTblWhts() {
		int[] tblWhts = new int[getTblColNo()];
		int cnt = 0;
		for(Iterator displayIt = getDisplayVO().iterator(); displayIt.hasNext();) {
		    if (cnt < getTblColNo()) {
		    	InquiryDisplayVO vo = (InquiryDisplayVO)displayIt.next();
			    tblWhts[cnt] = vo.getPdfTblColWidth().intValue();
			    cnt++;
		    } else {
		        break;
		    }
		}
	    return tblWhts;
	}
	
	protected int getHAlign(String hAlign) {
	    int h = 0;
	    hAlign = hAlign.toUpperCase().trim();
	    if (hAlign == null) {
	        h = Rectangle.ALIGN_RIGHT;
	    }
	    
	    if (hAlign.equals("CENTER")) {
	        h = Rectangle.ALIGN_CENTER;
	    } else if (hAlign.equals("LEFT")) {
	        h = Rectangle.ALIGN_LEFT;
	    } else if (hAlign.equals("RIGHT")) {
	        h = Rectangle.ALIGN_RIGHT;
	    } else {
	        h = Rectangle.ALIGN_RIGHT;
	    }
	    return h;
	}

	protected int getVAlign(String vAlign) {
	    int v = 0;
	    vAlign = vAlign.toUpperCase().trim();
	    if (vAlign == null) {
	        v = Rectangle.ALIGN_TOP;
	    }
	    
	    if (vAlign.equals("MIDDLE")) {
	        v = Rectangle.ALIGN_MIDDLE;
	    } else if (vAlign.equals("TOP")) {
	        v = Rectangle.ALIGN_TOP;
	    } else if (vAlign.equals("BOTTOM")) {
	        v = Rectangle.ALIGN_BOTTOM;
	    } else {
	        v = Rectangle.ALIGN_TOP;
	    }
	    
	    return v;
	}

	protected Collection getSpVO() {
	    return getMasterVO().getChilds(InquirySpVO.class);
	}
	
	protected GenericInquiryMasterVO getMasterVO() {
	    return form.getGenericInquiryMasterVO();
	}
	
	protected Collection getDisplayVO() {
	    return getMasterVO().getLocalChilds(InquiryDisplayVO.class);
	}
	
	public void initPage() {
	    try {
			for(Iterator spIt = getSpVO().iterator(); spIt.hasNext();) {
			    InquirySpVO spVO = (InquirySpVO)spIt.next();
			    compFontSiz = spVO.getPdfCompFontSize() == null? 0 : spVO.getPdfCompFontSize().intValue();
			    titleFontSiz = spVO.getPdfTitleFontSize() == null? 0 : spVO.getPdfTitleFontSize().intValue();
			    contentFontSiz = spVO.getPdfContentFontSize() == null? 0 : spVO.getPdfContentFontSize().intValue();
			    totalFontSiz = spVO.getPdfTotalFontSize() == null? 0 : spVO.getPdfTotalFontSize().intValue();
			    groupField = spVO.getPdfGroupField() == null? 0 : spVO.getPdfGroupField().intValue();
			    pageSize = spVO.getPdfPageSize() == null? defaultPageSize : spVO.getPdfPageSize();
			    pageRotate = spVO.getPdfPageRotate() == null? "" : spVO.getPdfPageRotate();
			    rptTitle = CommonUtil.nullToString(spVO.getInquiryName());
			    showCompLogo = CommonUtil.nullToString(spVO.getPdfCompLogo());
			}
		    String table = "T_COMPANY";
		    String column = "LONG_NAME";
		    String where = "COMPANY_CODE = '"+CommonUtil.nullToString(getMasterVO().getCompanyCode())+"' ";
		    compLongName = (String)sdg.findField(table, column, where);
		    
		    if (showCompLogo != null && showCompLogo.length() > 0 && (showCompLogo.equals("T") || showCompLogo.equals("L"))) {
			    byte[] logo = null;
			    table = "T_COMPANY";
			    column = "COMPANY_LOGO";
			    where = "COMPANY_CODE = '"+CommonUtil.nullToString(getMasterVO().getCompanyCode())+"' ";
			    logo = (byte[]) sdg.findField(table, column, where);
			    logo_img = Image.getInstance(logo);
			    logo_img.scaleAbsolute(100, 70);
		    }
	    } catch (Exception e) {
	        e.printStackTrace();
	    }
	}

	public ByteArrayOutputStream getReport(	ActionMapping mapping, ActionForm formIn,
			   HttpServletRequest request, HttpServletResponse response,
			   ActionErrors errors, Servlet servlet, ArrayList rs) 
	{	
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		
		form = (GenericInquirySearchForm) formIn;

		try {
		    initPage();
            Collection rsltList = form.getReportResultList();
            
    		Rectangle rect = new Rectangle(getPageSize());
            
			Document document = new Document(rect, 10, 10, 10, 30);
			PdfWriter writer = PdfWriter.getInstance(document, baos);
			HttpSession session = request.getSession(false);
			
			ServletContext servletContext = servlet.getServletConfig().getServletContext();

			compFt = new Font(Font.getFamilyIndex("Arial"), this.compFontSiz, Font.BOLD);
			titleFt = new Font(Font.getFamilyIndex("Arial"), titleFontSiz, Font.BOLD+ Font.UNDERLINE);
			subTitleFt = new Font(Font.getFamilyIndex("Arial"), contentFontSiz, Font.BOLD+ Font.UNDERLINE);//not use
			emptyFt = new Font(Font.getFamilyIndex("Arial"), 2, Font.NORMAL);
			sContentFtB = new Font(Font.getFamilyIndex("Arial"), contentFontSiz, Font.BOLD);
			sContentFt = new Font(Font.getFamilyIndex("Arial"), contentFontSiz, Font.NORMAL);
			totalFt = new Font(Font.getFamilyIndex("Arial"), totalFontSiz, Font.BOLD);
			editingUser =(User)session.getAttribute(ProjectConstants.SESSION_USER);

			MyPageEvents event = new MyPageEvents(formIn,session);
			writer.setPageEvent(event);
			document.open();
			
            if (!(getTblColNo() == 0)) {
                Table rsltTbl = new Table(getTblColNo());
                if (getRsltTblWhts().length > 0 && getRsltTblWhts().length == getTblColNo()){
                    rsltTbl.setWidth(100);
                    rsltTbl.setWidths(getRsltTblWhts());
                    rsltTbl.setCellspacing(2);
                    rsltTbl.setDefaultCellBorder(Rectangle.NO_BORDER);
                    rsltTbl.setBorder(Rectangle.NO_BORDER);	
                    rsltTbl.setCellsFitPage(true);	//if show description or remark, remove this setting
            		Cell cell = new Cell();
                    
            		int cnt1 = 0;
            		ArrayList hAlignList = new ArrayList();
            		ArrayList vAlignList = new ArrayList();
            		ArrayList summationFlagList = new ArrayList();
            		ArrayList colSpanList = new ArrayList();
            		for(Iterator disIt = getDisplayVO().iterator(); disIt.hasNext();) {
            		    if (cnt1 < getTblColNo()) {
                		    InquiryDisplayVO displayVO = (InquiryDisplayVO) disIt.next();
    						cell = new Cell(new Phrase(CommonUtil.nullToString(displayVO.getDispName()), sContentFt));//sContentFtB
    						cell.setHorizontalAlignment(getHAlign(displayVO.getPdfLblHAlign()));
    						cell.setBorder(Rectangle.BOTTOM);
    						rsltTbl.addCell(cell);
                		    hAlignList.add(cnt1,CommonUtil.nullToString(displayVO.getPdfHAlign()));
                		    vAlignList.add(cnt1,CommonUtil.nullToString(displayVO.getPdfVAlign()));
                		    summationFlagList.add(cnt1, displayVO.getPdfSummationFlag() == null? "N" : displayVO.getPdfSummationFlag());
                		    colSpanList.add(cnt1, CommonUtil.nullToString(displayVO.getPdfColSpan()));
                		    cnt1++;
            		    } else {
            		        break;
            		    }
            		}
            		rsltTbl.endHeaders();
        		    for(Iterator rsltIt = rsltList.iterator(); rsltIt.hasNext();) {
        		        InquiryOutputVO rsltVO = (InquiryOutputVO) rsltIt.next();
        		        if (rsltVO.getField(groupField - 1).equals("0")) {
            		        for(int i = 0; !(getTblColNo() == 0) && i < getTblColNo(); i++) {
	        		            cell = new Cell(new Phrase(CommonUtil.nullToString(rsltVO.getField(i)), sContentFt));
	        		            cell.setHorizontalAlignment(getHAlign((String)hAlignList.get(i)));
	        		            cell.setVerticalAlignment(getVAlign((String)vAlignList.get(i)));
	        		            rsltTbl.addCell(cell);
            		        }
        		        } else {
        		            int spanTtl = 0;
        		            String preValue = "";
        		            int cnt3 = 0;
            		        for(int i = 0; !(getTblColNo() == 0) && i < getTblColNo(); i++) { 
            		            	String dtlValue = CommonUtil.nullToString(rsltVO.getField(i));
            		            	int spanValue = CommonUtil.strToBigDecimal(CommonUtil.nullToString(colSpanList.get(i))).intValue();            		            	

//            		            	if(spanValue != 1 || (spanValue == 1 && !summationFlagList.get(i).equals("Y"))){
//            		            	    if(spanTtl>0){	 
//            		            	        addSpanCell(preValue, (String)hAlignList.get(i-1)
//            		            	                , (String)vAlignList.get(i-1), spanTtl, rsltTbl, summationFlagList, cnt3 - 1);
//            		            	    }
//            		            	    addSpanCell(dtlValue, (String)hAlignList.get(i)
//            		            	            , (String)vAlignList.get(i), 1, rsltTbl, summationFlagList, cnt3);
//            		            	    spanTtl = 0;
//            		            	}else{
//            		            	    spanTtl++;
//            		            	}
            		            	
            		            	if (spanValue==1 && !summationFlagList.get(i).equals("Y")) {
            		            		spanTtl++;
            		            	}else{
            		            		addSpanCell(dtlValue, (String)hAlignList.get(i)
            		            	            , (String)vAlignList.get(i), spanTtl+1, rsltTbl, summationFlagList, cnt3);
            		            	    	spanTtl = 0;
            		            	}
            		            	
            		            	preValue = dtlValue;
            		            	cnt3++;
            		        }
		            	    if(spanTtl>0){	
		            	        addSpanCell(preValue, (String)hAlignList.get(getTblColNo()-1)
		            	                , (String)vAlignList.get(getTblColNo()-1), spanTtl, rsltTbl
		            	                , summationFlagList, getTblColNo() - 1);
		            	    }
            		        
        		        }
        		    }
            		document.add(rsltTbl);
                }
            }
			document.close();
		} catch(Exception e) {
		    e.printStackTrace();
		}
		
		return baos;
	}
	
	public void addSpanCell(String preValue, String hAlign, String vAlign, int spanTtl, Table rsltTbl
	        , ArrayList summationFlagList, int i) {
	    try {
	        Cell cell = new Cell(new Phrase(preValue, totalFt));
		    cell.setHorizontalAlignment(getHAlign(hAlign));
		    cell.setVerticalAlignment(getVAlign(vAlign));
		    cell.setColspan(spanTtl);
		    if (summationFlagList.get(i).equals("Y")) cell.setBorder(Rectangle.TOP); 
		    rsltTbl.addCell(cell);
	    } catch(Exception e) {
	        e.printStackTrace();
	    }
	}
    
	class MyPageEvents extends PdfPageEventHelper
	{
	    ActionForm formIn;
	    PdfContentByte cb;
		PdfTemplate template;
		BaseFont bf = null;
		final int FONT_SIZE = 7;
	    float pageYPos = 0;

	    float tableBottom1 = 0;
	    float xAxis = 0;
	    HttpSession session;
		
	    
	    public MyPageEvents(ActionForm formIn,HttpSession session){
	    	try{
		    	this.formIn = formIn;
		    	this.session = session;
	    	}catch(Exception e){
	    		e.printStackTrace();
	    	}

	    }
	    
	    public void onOpenDocument(PdfWriter writer, Document document) {
	        try {
	        	bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
	            cb = writer.getDirectContent();
	            template = cb.createTemplate(50, 50);
	        }
	        catch(Exception e) {
	        }
	    }

	    public void onCloseDocument(PdfWriter writer, Document document) {
	        template.beginText();
	        template.setFontAndSize(bf, FONT_SIZE);
	        template.showText(String.valueOf(writer.getPageNumber() - 1));
	        template.endText();
	    }

	    public void onStartPage(PdfWriter writer, Document document) {   
	    	try{
		        int pageN = writer.getPageNumber();        
		        String text = "Page " + pageN + " of ";
		        pageYPos = document.bottomMargin() - 13;
		        xAxis = bf.getWidthPoint(text, FONT_SIZE);
		        setRptComp(document);
		        setRptHeader(document);

		        float len = bf.getWidthPoint(text, FONT_SIZE);
		
		        cb.beginText();
		        cb.setFontAndSize(bf, FONT_SIZE);
		        if (pageRotate.equals("Y")) {
			        cb.setTextMatrix(476 - len , pageYPos-tableBottom1);
		        } else if (pageRotate.equals("N")) {
		            cb.setTextMatrix(300 - len , pageYPos-tableBottom1);
		        }

		        cb.showText(text);
		        cb.endText();

		        if (pageRotate.equals("Y")) {
			        cb.addTemplate(template, 476, pageYPos-tableBottom1);
		        } else if (pageRotate.equals("N")) {
			        cb.addTemplate(template, 300, pageYPos-tableBottom1);
		        }
		        

		        cb.beginText();
		        cb.setFontAndSize(bf, FONT_SIZE);
		        cb.setTextMatrix(280, 820);		            

		        cb.endText();
	    	}catch(Exception e){
	    		e.printStackTrace();
	    	}
	    }
	    
	    public void setRptComp(Document document){

		    try {
			    int[] compTblWths = {40, 60};
			    PdfPTable compTbl = new PdfPTable(2);
			    compTbl.setWidths(compTblWths);
			    compTbl.setWidthPercentage(80);
			    PdfPCell pCell = new PdfPCell();
 
	            PdfPCell emptyLineCell = new PdfPCell(new Phrase("", emptyFt));
	            emptyLineCell.setBorder(Rectangle.NO_BORDER);
	            emptyLineCell.setColspan(2);
	            
	            if (showCompLogo.equals("T") || showCompLogo.equals("L")) {
	                PdfPCell logoC = new PdfPCell(logo_img);
	                logoC.setBorder(Rectangle.NO_BORDER);
	                if (showCompLogo.equals("T")) {
	                    logoC.setColspan(2);
	                    logoC.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
	                    compTbl.addCell(logoC);
	                } else if (showCompLogo.equals("L")) {
	                    logoC.setHorizontalAlignment(Rectangle.ALIGN_RIGHT);
	                    compTbl.addCell(logoC);
	                }
	            }
			    pCell = new PdfPCell(new Phrase(compLongName, compFt));
			    pCell.setBorder(Rectangle.NO_BORDER);
			    if (showCompLogo.equals("T") || logo_img == null) {
			        pCell.setColspan(2);
			    }
			    if (showCompLogo.equals("L")) {
			        pCell.setHorizontalAlignment(Rectangle.ALIGN_LEFT);
			        pCell.setVerticalAlignment(Rectangle.ALIGN_MIDDLE);
			    } else {
			        pCell.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
			    }
			    compTbl.addCell(pCell);
			    
			    compTbl.addCell(emptyLineCell);
			    
	            pCell = new PdfPCell(new Phrase(rptTitle, titleFt));
	            pCell.setBorder(Rectangle.NO_BORDER);
	            pCell.setColspan(2);
	            pCell.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
	            compTbl.addCell(pCell);
			    compTbl.addCell(emptyLineCell);
			    
			    document.add(compTbl);
		    } catch (Exception e) {
		        e.printStackTrace();
		    }
	    }
	    
	    public void setRptHeader(Document document) {
	        try {
	            InquiryCriteriaVO critVO = null;
	            GenericInquiryMasterVO vo = form.getGenericInquiryMasterVO();
	            Collection critLblList = vo.getLocalChilds(InquiryCriteriaVO.class);
	            String[] critLbl = {};
				String systemDate = CommonUtil.nullToString(CommonUtil.dateToString(new Date(),CommonUtil.OUTPUT_DATETIME_FORMAT));		

//				int[] hdrTblWths = {10, 7, 3, 7, 40, 12, 9, 3, 9};
				int[] hdrTblWths = {14, 8, 3, 8, 34, 14, 8, 3, 8};
	            PdfPTable hdrTbl = new PdfPTable(9);
	            hdrTbl.setWidths(hdrTblWths);
	            hdrTbl.setWidthPercentage(100);

	            PdfPCell pCell = new PdfPCell();
	            
	            PdfPCell emptyCell = new PdfPCell(new Phrase("", sContentFt));
	            emptyCell.setBorder(Rectangle.NO_BORDER);
	            
	            PdfPCell emptyLineCell = new PdfPCell(new Phrase("", emptyFt));
	            emptyLineCell.setBorder(Rectangle.NO_BORDER);
	            emptyLineCell.setColspan(9);
	            String[] dateLine = {"Print Date:", systemDate, "", "", "", "", ""};
	            String[] userLine = {"Print User:", editingUser.getUserName(), "", "", "", "", "", ""};
	            
	            for (int j = 0; dateLine != null && j < dateLine.length; j++) {
	                if (j%2 == 0)  pCell = new PdfPCell(new Phrase(dateLine[j], sContentFtB));
		            else pCell = new PdfPCell(new Phrase(dateLine[j], sContentFt));
		            pCell.setBorder(Rectangle.NO_BORDER);
		            if (j == 1) pCell.setColspan(3);
		            hdrTbl.addCell(pCell);
	            }
	            for (int k = 0; userLine != null && k < userLine.length; k++) {
	                if (k%2 == 0) pCell = new PdfPCell(new Phrase(userLine[k], sContentFtB));
	                else pCell = new PdfPCell(new Phrase(userLine[k], sContentFt));
		            pCell.setBorder(Rectangle.NO_BORDER);
		            if (k == 1) pCell.setColspan(2);
		            hdrTbl.addCell(pCell);
	            }
	            
	            int cnt = 0;
	            for (Iterator critIt = critLblList.iterator(); critIt.hasNext();) {
	                critVO = (InquiryCriteriaVO)critIt.next();
	                if (critVO.getFieldType().equals(GenericInquiryConstants.FIELD_TYPE_TEXT_FM_TO) || critVO.getFieldType().equals(GenericInquiryConstants.FIELD_TYPE_TEXT_FM_TO_OC)) {
	                    pCell = new PdfPCell(new Phrase(CommonUtil.nullToString(critVO.getFieldName()) + ":", sContentFtB));
	                    pCell.setBorder(Rectangle.NO_BORDER);
	                    hdrTbl.addCell(pCell);
	                    pCell = new PdfPCell(new Phrase(CommonUtil.nullToString(form.getSrchFrom()[cnt]), sContentFt));
	                    pCell.setBorder(Rectangle.NO_BORDER);
	                    hdrTbl.addCell(pCell);
	                    pCell = new PdfPCell(new Phrase(" to ", sContentFtB));
	                    pCell.setBorder(Rectangle.NO_BORDER);
	                    hdrTbl.addCell(pCell);
	                    pCell = new PdfPCell(new Phrase(CommonUtil.nullToString(form.getSrchTo()[cnt]), sContentFt));
	                    pCell.setBorder(Rectangle.NO_BORDER);
	                    hdrTbl.addCell(pCell);
	                } else if (critVO.getFieldType().equals(GenericInquiryConstants.FIELD_TYPE_DROP_DOWN) ||
	                        critVO.getFieldType().equals(GenericInquiryConstants.FIELD_TYPE_DROP_DOWN_OC) ||
	                        critVO.getFieldType().equals(GenericInquiryConstants.FIELD_TYPE_MULTIPLE_DROP_DOWN) ||
	                        critVO.getFieldType().equals(GenericInquiryConstants.FIELD_TYPE_POPUP_SELECT) ||
	                        critVO.getFieldType().equals(GenericInquiryConstants.FIELD_TYPE_POPUP_SELECT_MULTIPLE) ||
	                        critVO.getFieldType().equals(GenericInquiryConstants.FIELD_TYPE_MULTIBOX) ||
	                        critVO.getFieldType().equals(GenericInquiryConstants.FIELD_TYPE_MULTIBOX_HORIZONTAL) ||
	                        critVO.getFieldType().equals(GenericInquiryConstants.FIELD_TYPE_MULTIPLE_DROP_DOWN)) {
	                    pCell = new PdfPCell(new Phrase(CommonUtil.nullToString(critVO.getFieldName()) + ":", sContentFtB));
	                    pCell.setBorder(Rectangle.NO_BORDER);
	                    hdrTbl.addCell(pCell);
	                    pCell = new PdfPCell(new Phrase(CommonUtil.nullToString(form.getSrchFromLabel()[cnt]), sContentFt));
	                    pCell.setColspan(3);
	                    pCell.setBorder(Rectangle.NO_BORDER);
	                    hdrTbl.addCell(pCell);
	                } else {
	                    pCell = new PdfPCell(new Phrase(CommonUtil.nullToString(critVO.getFieldName()) + ":", sContentFtB));
	                    pCell.setBorder(Rectangle.NO_BORDER);
	                    hdrTbl.addCell(pCell);
//	                    pCell = new PdfPCell(new Phrase(CommonUtil.nullToString(form.getSrchFromLabel()[cnt]), sContentFt));
	                    pCell = new PdfPCell(new Phrase(CommonUtil.nullToString(form.getSrchFrom()[cnt]), sContentFt));
	                    pCell.setBorder(Rectangle.NO_BORDER);
	                    pCell.setColspan(3);
	                    hdrTbl.addCell(pCell);
	                }
	                if (cnt%2 == 0)  hdrTbl.addCell(emptyCell);
	                cnt++;
	            }
	            hdrTbl.addCell(emptyLineCell);
	            document.add(hdrTbl);
				float [] cellsWidth = hdrTbl.getAbsoluteWidths();
				float tblWidth = hdrTbl.getTotalWidth()/2;
				
				pageXPos = tblWidth;
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	    }
	}
}

